package com.survey.Controller;


import com.survey.pojo.data.SurveyDO;
import com.survey.pojo.vo.SurveyVO;
import com.survey.service.SurveyService;
import com.survey.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 邱思雨和王晓专用
 */
@Controller
@RequestMapping("/admin/survey")
public class SurveyManageController {
    @Autowired
    SurveyService surveyService;

    @RequestMapping("/surveyEdit")
    public String surveyEdit(Integer sid, Model model) throws Exception {
        System.out.println(sid);
        SurveyVO surveyVO = new SurveyVO();
        surveyVO.setId(sid);
        SurveyDO detailSurvey = surveyService.findDetailSurvey(surveyVO);
        model.addAttribute("survey", detailSurvey);
        return "/admin/SurveyEdit.jsp";
    }

    //    /survey/editSurvey
    @RequestMapping("/editSurvey")
    @ResponseBody
    public Result editSurvey(SurveyVO surveyVO,boolean isopenBoolean, Model model,String endtime) throws Exception {

        surveyVO.setIsopen(1);
        if(isopenBoolean){
            surveyVO.setIsopen(0);
        }
        return surveyService.updateSurvey(surveyVO);
    }
}
